const path = require("path");
const channelInfo = require('./channel');

const config = {
  projectName: 'caster-new',
  date: '2020-10-29',
  designWidth: 750,
  deviceRatio: {
    640: 2.34 / 2,
    750: 1,
    828: 1.81 / 2
  },
  sourceRoot: 'src',
  outputRoot: 'dist',
  alias: {
    '@': path.resolve(__dirname, '..', 'src'),
    '@@/channel': path.resolve(__dirname, '..', 'src/appId/' + channelInfo.appId),
    '@@/app_style': path.resolve(__dirname, '..', 'src/appId/' + channelInfo.appId + '/app.scss'),
  },
  plugins: [],
  defineConstants: {
    CURRENT_APPID: JSON.stringify(channelInfo.appId), //当前小程序Id
    ASSETS_PATH: JSON.stringify('https://leconglive-wxapp-1301839528.file.myqcloud.com/' + channelInfo.appId),
  },
  copy: {
    patterns: [
      // { from: 'src/workers', to: 'dist/workers' } // from:源文件中workers的路径，to:编译后的路径
      {
        from: 'config/' + channelInfo.appId + '/project.config.json',
        to: 'project.config.json'
      }
    ],
    options: {}
  },
  framework: 'react',
  mini: {
    postcss: {
      pxtransform: {
        enable: true,
        config: {

        }
      },
      url: {
        enable: true,
        config: {
          limit: 1024 // 设定转换尺寸上限
        }
      },
      cssModules: {
        enable: false, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: 'module', // 转换模式，取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]'
        }
      }
    }
  },
  h5: {
    publicPath: '/',
    staticDirectory: 'static',
    esnextModules: ['taro-cropper-v3'],
    postcss: {
      autoprefixer: {
        enable: true,
        config: {
        }
      },
      cssModules: {
        enable: false, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: 'module', // 转换模式，取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]'
        }
      }
    }
  }
}

module.exports = function (merge) {
  let envConfig;
  if (process.env.NODE_ENV === 'development') {
    envConfig = require('./dev')
    // return merge({}, config, require('./dev'))
  } else {
    envConfig = require('./prod')
    // return merge({}, config, require('./prod'))

  }

  return merge({}, config, envConfig, require('./' + channelInfo.appId + '/config'))
}


//需要使用cross-env依赖
// module.exports = function (merge) {
//   const buildConfig = {
//     env: {
//       BUILD_ENV: JSON.stringify(process.env.NODE_ENV)
//     }
//   }
//   if (process.env.NODE_ENV === 'dev') {
//     return merge({}, config, require('./dev'), buildConfig)
//   }
//   if (process.env.NODE_ENV === 'pre') {
//     return merge({}, config, require('./pre'), buildConfig)
//   }
//   return merge({}, config, require('./prod'), buildConfig)
// }
